package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class INDEXOF extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if ((paramArrayOfObject.length < 2) || (paramArrayOfObject.length > 2))
      return Primitive.ERROR_VALUE;
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    String str = localObject1.toString();
    if (localObject2 instanceof Integer)
    {
      int i = ((Integer)localObject2).intValue();
      char[] arrayOfChar = str.toCharArray();
      if ((i < 0) || (i >= arrayOfChar.length))
        return Primitive.ERROR_VALUE;
      char c = arrayOfChar[i];
      return new Character(c);
    }
    return Primitive.ERROR_VALUE;
  }

  public Function.Type getType()
  {
    return Function.TEXT;
  }

  public String getCN()
  {
    return "INDEXOF(str1，index):返回字符串str1在index位置上的字符。\n备注:\n    index是从0开始计数的。\n示例:\nINDEXOF(\"FineReport\",0)等于'F'。\nINDEXOF(\"FineReport\",2)等于'n'。\nINDEXOF(\"FineReport\"，9)等于't'。\n\nINDEXOF(array, index):返回数组在index位置上的元素。\n备注：\n    index是从1开始计数的。\n示例：\nString[] array = {\"a\", \"b\", \"c\"}\nINDEXOF(array, 1)等于\"a\".\n";
  }

  public String getEN()
  {
    return "INDEXOF(string1,index): Returns the char at the index of string1.\n\nRemarks:\nindex count from 0.\n\nExample:\nINDEXOF(\"FineReport\",0) returns 'F'.\nINDEXOF(\"FineReport\",2) returns 'n'.\nINDEXOF(\"FineReport\"，9) returns 't'.\n\nINDEXOF(array, index):Returns the element at the index of array.\nRemarks：\n    index count from 1.\nExample：\nString[] array = {\"a\", \"b\", \"c\"}\nINDEXOF(array, 1) returns \"a\".";
  }
}